<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>login</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            $("form").submit(function () {
                $.ajax({
                    url:"login",
                    method:"post",
                    data:{username:$("#name").val(),password:$("#pass").val()},
                    success(d,status){
                        //alert(JSON.stringify(d)+">>>>>>>>>>"+status);
                        if(d.code==200){
                            window.sessionStorage.setItem("token",d.data);
                            //alert(window.sessionStorage.getItem("token"));
                            location='student.html';
                        }else{
                            alert("error,原因是：code="+d.code+","+d.msg);
                        }
                    },
                    error:function (d) {
                        alert(d.responseText);
                    },
                    complete:function (d) {
                        //alert("????"+JSON.stringify(d)+","+d.status);
                    }
                })

                return false;
            });
        });
    </script>
</head>
<body>
  <form action="admin/login">
      <input name="name" id="name" placeholder="name"/>
      <input name="pass" id="pass" placeholder="password"/>
      <input type="submit" value="login"/>
  </form>
</body>
</html>